#region Using Directives

using System;
using System.Web;
using System.Web.UI;
using Eneta.Portal.Forum.Controls.Base;
using Eneta.Portal.Forum.Core.Domain.Entities;
using Eneta.Portal.Forum.Core.Service.Application;

#endregion

namespace Eneta.Portal.Forum.Controls
{
    public class ViewProfile : BaseForumControl
    {
        #region Protected Methods
        protected override void CreateChildControls()
        {
            ForumUser user = null;
            var userId = ValidInt(HttpContext.Current.Request.QueryString["userid"]);
            if (userId != 0)
            {
                user = RepositoryRegistry.ForumUserRepository.GetBySharePointId(userId);
            }
            if (null == user)
            {
                user = ForumApplication.Instance.CurrentUser;
            }

            Controls.Add(BuildPageLinks(user.Name, ForumApplication.Instance.GetLink(SharePointForumControls.ViewProfile)));

            AddBoxHeader(String.Format("{0} {1}", Resources.UI.UserInfoBoxView, user.Name), false, 2);

            AddUserDetailRow(Resources.UI.UserInfoBoxJoined, user.Joined.ToString());
            AddUserDetailRow(Resources.UI.UserInfoBoxLastVisit, user.LastVisit.ToString());
            AddUserDetailRow(Resources.UI.UserInfoBoxNumberOfPosts, user.NumPosts.ToString());
            AddUserDetailRow(Resources.UI.UserInfoBoxEmail, String.Format("<a href=\"mailto:{0}\">{0}</a>", user.Email));

            CloseBox();
        }
        #endregion

        #region Private Methods
        private void AddUserDetailRow(string label, string text)
        {
            Controls.Add(new LiteralControl(String.Format("<tr><td align=right class=ms-navframe><strong>{0}</strong></td><td>{1}</td></tr>", label, text)));
        }
        #endregion
    }
}